<script src="jquery.js"></script>
<html>
<?php
	include "../Questionnaire.php";
	
	$paper=new Questionnaire();
	if(isset($_GET['subject']) && isset($_GET['date']))
	{
		$paper->getQuestionnaire("select * from questionnaire q,exam e where q.examcode=e.examcode and q.subject='".$_GET['subject']."' and e.examdate<CURDATE() and e.avail=0");

	}
	else
	{	
		$paper->getQuestionnaire("select * from questionnaire q,exam e where q.examcode=e.examcode and e.avail=1 and e.examdate=CURDATE()");
	}
	
	
?>

<script>
var options = new Object();
var count;
var element;
var json;
$(function(){	
	count=$("#count").text();
	if(count>0)
	{
		$("#ques_submit").click(function(){
			$(".question").each(function(){
				//options[$("input[type='hidden']",this).val()]=$("input[type='radio']:").val();
				element = $("input[type='hidden']",this);
				if($("input:radio[name="+element.attr("id")+"]:checked").is(":checked")) {
					options[element.val()]=$("input:radio[name="+element.attr("id")+"]:checked").val();
				}
			
			});
		
			json=JSON.stringify(options);
			var answered=0;
			for(i in options) {
				answered=answered+1;
			}
			if(count!=answered)
			{
				var res=confirm("You didnot answer all the questions.Do you want to submit?");
				if(res==true)
					postAnswers();
				else
					removeAnswered();
			}
			else
				postAnswers();
		});
	}
});

function removeAnswered()
{
	$(".question").each(function(){
		if($("input:radio",this).is(":checked"))
		{
			$(this).hide();
		}
	});
}

function postAnswers()
{
	$.post("answer_evaluation.php?seed="+Math.random(),
		{
			answers:json,
			maxmarks:count
		},function(data){
			//alert(data);
			$("#content").html(data);
	});
}


</script>

